/******************************************************************************
 * * contact_settings.c - implementation of contact settings functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "contact_global.h"

/**
 * Action if pressing memory button on Contacts_Display interface
 * param (in) lv_obj_t *Btn,lv_event_t event
 * return  void
 */
void Contacts_Display_Btn_Memory_Cb(lv_obj_t *Btn,lv_event_t event)
{
    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    UI_List_Desc_t   *List =
        &(((UI_Normal_List_Only_Desc_t *)g_ContactsMng.InterfaceCtrl.Ctrl)->List);
    UI_Button_Desc_t *BtnList = List->ButtonList;
    lv_obj_t         *Image   = lv_obj_get_child_back(BtnList[List->Index].Button, NULL);

    if (2 == List->Index) // SIM2
    {
        if (0 != (BtnList[0].ButtonIndex & CONTACTS_MEMSEL_SIM2))
        {
            BtnList[2].SymbolId1 = SYMBOL_NOT_CHECKED;
            lv_img_set_src(Image, SYMBOL_NOT_CHECKED);
            BtnList[0].ButtonIndex &= ~CONTACTS_MEMSEL_SIM2;
        }
        else
        {
            BtnList[2].SymbolId1 = SYMBOL_CHECKED;
            lv_img_set_src(Image, SYMBOL_CHECKED);
            BtnList[0].ButtonIndex |= CONTACTS_MEMSEL_SIM2;
        }
    }
    else if (1 == List->Index) /*SIM1 or SIM2*/
    {
        if (CONTACTS_PHONEBOOK_STATUS_READ_DONE == g_ContactsMng.PhonebookStatus[0]) // SIM1
        {
            if (0 != (BtnList[0].ButtonIndex & CONTACTS_MEMSEL_SIM1))
            {
                BtnList[1].SymbolId1 = SYMBOL_NOT_CHECKED;
                lv_img_set_src(Image, SYMBOL_NOT_CHECKED);
                BtnList[0].ButtonIndex &= ~CONTACTS_MEMSEL_SIM1;
            }
            else
            {
                BtnList[1].SymbolId1 = SYMBOL_CHECKED;
                lv_img_set_src(Image, SYMBOL_CHECKED);
                BtnList[0].ButtonIndex |= CONTACTS_MEMSEL_SIM1;
            }
        }
        else // SIM2
        {
            if (0 != (BtnList[0].ButtonIndex & CONTACTS_MEMSEL_SIM2))
            {
                BtnList[1].SymbolId1 = SYMBOL_NOT_CHECKED;
                lv_img_set_src(Image, SYMBOL_NOT_CHECKED);
                BtnList[0].ButtonIndex &= ~CONTACTS_MEMSEL_SIM2;
            }
            else
            {
                BtnList[1].SymbolId1 = SYMBOL_CHECKED;
                lv_img_set_src(Image, SYMBOL_CHECKED);
                BtnList[0].ButtonIndex |= CONTACTS_MEMSEL_SIM2;
            }
        }
    }
    else
    {
        if (0 != (BtnList[0].ButtonIndex & CONTACTS_MEMSEL_PHONE))
        {
            BtnList[0].SymbolId1 = SYMBOL_NOT_CHECKED;
            lv_img_set_src(Image, SYMBOL_NOT_CHECKED);
            BtnList[0].ButtonIndex &= ~CONTACTS_MEMSEL_PHONE;
        }
        else
        {
            BtnList[0].SymbolId1 = SYMBOL_CHECKED;
            lv_img_set_src(Image, SYMBOL_CHECKED);
            BtnList[0].ButtonIndex |= CONTACTS_MEMSEL_PHONE;
        }
    }
} /* Contacts_Display_Btn_Memory_Cb */

/**
 * Callback function for handling key pressed on Contacts_Display interface
 * param (in) Obj: lv_obj_t *
 * param (in) Key_Sta: UI_KEY_STATUS
 * param (in) Key_Val: UI_KEY_VALUE
 * return  UINT8
 */
UINT8 Contacts_Display_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    UINT8            Ret      = 1;                          // not call default key function for List
    UI_Button_Desc_t *BtnList =
        ((UI_Normal_List_Only_Desc_t *)g_ContactsMng.InterfaceCtrl.Ctrl)->List.ButtonList;
    Contacts_List_t  *Contact = NULL;
    Contacts_List_t  *Node    = NULL;
    UINT8            MemSel;

    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTLEFT: // save changes
            MemSel = BtnList[0].ButtonIndex;
            if (CONTACTS_PHONEBOOK_STATUS_SIM_ABSENT == g_ContactsMng.PhonebookStatus[0])
            {
                MemSel &= ~CONTACTS_MEMSEL_SIM1;
            }
            if (CONTACTS_PHONEBOOK_STATUS_SIM_ABSENT == g_ContactsMng.PhonebookStatus[1])
            {
                MemSel &= ~CONTACTS_MEMSEL_SIM2;
            }

            if (0 == MemSel) // no memory selected
            {
                break;
            }

            if (BtnList[0].ButtonIndex == g_ContactsMng.ContactsMemSel.MemSel) // selected memory not changed
            {
                Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS, NULL, NULL);
                break;
            }

            g_ContactsMng.ContactsMemSel.MemSel = BtnList[0].ButtonIndex;

            MemSel = g_ContactsMng.ContactsMemSel.MemSel;
            UI_NV_Write_Req(NV_SECTION_UI_CONTACTS_BITMAP, NV_CONTACTS_MAX_BITMAP_LEN, 1, &MemSel);

            _lv_ll_clear(&g_ContactsMng.ContactsMemSel.ListForSpecMem);
            g_ContactsMng.ContactsMemSel.ContactsCount = 0;

            if (CONTACTS_MEMSEL_ALL != MemSel)
            {
                if (0 == g_ContactsMng.PhkStatus[CONTACTS_MEMORY_PHONE].Used)
                {
                    MemSel &= ~CONTACTS_MEMSEL_PHONE;
                }
                if (0 == g_ContactsMng.PhkStatus[CONTACTS_MEMORY_SIM1].Used)
                {
                    MemSel &= ~CONTACTS_MEMSEL_SIM1;
                }
                if (0 == g_ContactsMng.PhkStatus[CONTACTS_MEMORY_SIM2].Used)
                {
                    MemSel &= ~CONTACTS_MEMSEL_SIM2;
                }

                if (0 != MemSel)
                {
                    Node = _lv_ll_get_head(&g_ContactsMng.ContactsList);
                    while (NULL != Node)
                    {
                        if (Contacts_Is_In_MemSel(Node->ContactInfo->MemoryAndIndex, MemSel))
                        {
                            Contact              = _lv_ll_ins_tail(&g_ContactsMng.ContactsMemSel.ListForSpecMem);
                            Contact->ContactInfo = Node->ContactInfo;
                            g_ContactsMng.ContactsMemSel.ContactsCount++;
                        }

                        Node = _lv_ll_get_next(&g_ContactsMng.ContactsList, Node);
                    }
                }
            }

            Contacts_Reset_Contacts_Interface();

            Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS, NULL, NULL);
            break;

        case KEY_SOFTRIGHT: // not save changes
            Nav_Back(ACT_ID_ANY);
            break;

        case KEY_END: // not save changes
            Nav_Home(ACT_ID_ANY);
            break;

        case KEY_OK:
        case KEY_UP:
        case KEY_DOWN:
        case KEY_LEFT:
        case KEY_RIGHT:
            Contacts_Press_Direction_Key_On_List(Key_Val);
            Ret = 0; // call default key function for List
            break;

        default:
            break;
        } /* switch */
    }

    return(Ret);
} /* Contacts_Display_Key_Cb */

/**
 * Callback function for restoring state on Contacts_Display interface after backward from another activity
 * param (in) Ctrl: VOID *
 * return  VOID
 */
VOID Contacts_Display_OnRestoreState(VOID *Ctrl)
{
    g_ContactsMng.InterfaceCtrl.Ctrl        = Ctrl;
    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_DISPLAY;
}

/**
 * Create Contacts_Display interface
 * param (in) VOID
 * return  VOID
 */
VOID Contacts_Create_Contacts_Display(VOID)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;
    UINT32                     Len;
    UINT8                      i = 0;

    NormalLstOnlyDesc =
        (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_DISPLAY;
    g_ContactsMng.InterfaceCtrl.Ctrl        = (VOID *)NormalLstOnlyDesc;

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_DISPLAY_CONTACTS;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLstOnlyDesc->List.ListButtonCnt = 1;
    if (CONTACTS_PHONEBOOK_STATUS_READ_DONE == g_ContactsMng.PhonebookStatus[0])
    {
        NormalLstOnlyDesc->List.ListButtonCnt++;
    }
    if (CONTACTS_PHONEBOOK_STATUS_READ_DONE == g_ContactsMng.PhonebookStatus[1])
    {
        NormalLstOnlyDesc->List.ListButtonCnt++;
    }
    Len = sizeof(UI_Button_Desc_t) *
          NormalLstOnlyDesc->List.ListButtonCnt;
    NormalLstOnlyDesc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(Len);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, Len);

    NormalLstOnlyDesc->List.ButtonList[i].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId       = PHONE_TEXT_ID_PHONE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex = g_ContactsMng.ContactsMemSel.MemSel;
    UI_Log_Out(UI_SUB_MODULE_FRAMEWORK, UI_LOG_LEVEL_TRACE_1, "Contacts_Create_Contacts_Display, Memsel %d\n", g_ContactsMng.ContactsMemSel.MemSel);
    if (0 != (g_ContactsMng.ContactsMemSel.MemSel & CONTACTS_MEMSEL_PHONE))
    {
        NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_CHECKED;
    }
    else
    {
        NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_NOT_CHECKED;
    }
    NormalLstOnlyDesc->List.ButtonList[i].ReleaseFun = Contacts_Display_Btn_Memory_Cb;
    i++;

    if (CONTACTS_PHONEBOOK_STATUS_READ_DONE == g_ContactsMng.PhonebookStatus[0])
    {
        NormalLstOnlyDesc->List.ButtonList[i].Valid = TRUE;
        NormalLstOnlyDesc->List.ButtonList[i].TxtId = PHONE_TEXT_ID_SIM1;
        if (0 != (g_ContactsMng.ContactsMemSel.MemSel & CONTACTS_MEMSEL_SIM1))
        {
            NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_CHECKED;
        }
        else
        {
            NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_NOT_CHECKED;
        }
        NormalLstOnlyDesc->List.ButtonList[i].ReleaseFun = Contacts_Display_Btn_Memory_Cb;
        i++;
    }

    if (CONTACTS_PHONEBOOK_STATUS_READ_DONE == g_ContactsMng.PhonebookStatus[1])
    {
        NormalLstOnlyDesc->List.ButtonList[i].Valid = TRUE;
        NormalLstOnlyDesc->List.ButtonList[i].TxtId = PHONE_TEXT_ID_SIM2;
        if (0 != (g_ContactsMng.ContactsMemSel.MemSel & CONTACTS_MEMSEL_SIM2))
        {
            NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_CHECKED;
        }
        else
        {
            NormalLstOnlyDesc->List.ButtonList[i].SymbolId1 = SYMBOL_NOT_CHECKED;
        }
        NormalLstOnlyDesc->List.ButtonList[i].ReleaseFun = Contacts_Display_Btn_Memory_Cb;
    }

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonL.TxtId = PHONE_TEXT_ID_SAVE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Contacts_Display_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_List_Only_Create;
    FuncList.OnRestoreState = Contacts_Display_OnRestoreState;
    FuncList.OnDestroy      = Contacts_Normal_List_Interface_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS_DISPLAY, &FuncList, g_ContactsMng.InterfaceCtrl.Ctrl);
} /* Contacts_Create_Contacts_Display */

/**
 * Callback function for handling key pressed on Contacts_Memory_Status interface
 * param (in) Obj: lv_obj_t *
 * param (in) Key_Sta: UI_KEY_STATUS
 * param (in) Key_Val: UI_KEY_VALUE
 * return  UINT8
 */
UINT8 Contacts_Memory_Status_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    UI_Normal_NoTitle_Ta_Desc_t *Interface =
        (UI_Normal_NoTitle_Ta_Desc_t *)g_ContactsMng.InterfaceCtrl.Ctrl;

    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
            Nav_Back(ACT_ID_ANY);
            break;

        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            break;

        case KEY_UP:
        case KEY_DOWN:
            if (0 == lv_textarea_get_cursor_pos(Interface->ContTa.TextArea))
            {
                /* set the curson to the end of text on TA */
                lv_textarea_set_cursor_pos(Interface->ContTa.TextArea, -1);
            }
            else
            {
                /* set the curson to the top of text on TA */
                lv_textarea_set_cursor_pos(Interface->ContTa.TextArea, 0);
            }
            break;

        default:
            break;
        } /* switch */
    }

    return(1);
}

/**
 * Callback function for additional actions after Creating Contacts_Memory_Status interface
 * param (in) Ctrl: VOID *
 * return  VOID
 */
VOID Contacts_Memory_Status_OnCreate(VOID *Ctrl)
{
    UI_Normal_NoTitle_Ta_Desc_t *Interface = (UI_Normal_NoTitle_Ta_Desc_t *)Ctrl;

    /* set the cursor to the top of text on TA */
    lv_textarea_set_cursor_pos(Interface->ContTa.TextArea, 0);
}

/**
 * Callback function for restoring state on Contacts_Memory_Status interface after backward from another activity
 * param (in) Ctrl: VOID *
 * return  VOID
 */
VOID Contacts_Memory_Status_OnRestoreState(VOID *Ctrl)
{
    UI_Normal_NoTitle_Ta_Desc_t *Interface = (UI_Normal_NoTitle_Ta_Desc_t *)Ctrl;

    g_ContactsMng.InterfaceCtrl.Ctrl        = Ctrl;
    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_NOSCREEN_DELETE;

    if (0 == lv_textarea_get_cursor_pos(Interface->ContTa.TextArea))
    {
        /* set the cursor to the end of text on TA */
        lv_textarea_set_cursor_pos(Interface->ContTa.TextArea, -1);
    }
    else
    {
        /* set the cursor to the top of text on TA */
        lv_textarea_set_cursor_pos(Interface->ContTa.TextArea, 0);
    }
}

/**
 * Callback function for destroying Contacts_Memory_Status interface which will be popped from stack
 * param (in) Ctrl: VOID *
 * return  VOID
 */
VOID Contacts_Memory_Status_OnDestroy(VOID *Ctrl)
{
    UI_Normal_NoTitle_Ta_Desc_t *Interface = (UI_Normal_NoTitle_Ta_Desc_t *)Ctrl;

    Hal_Mem_Free(Interface->ContTa.TaTxt);
    Hal_Mem_Free(Ctrl);
}

/**
 * Create Contacts_Memory_Status interface
 * param (in) VOID
 * return  VOID
 */
VOID Contacts_Create_Contacts_Memory_Status(VOID)
{
    UI_Normal_NoTitle_Ta_Desc_t *Interface;
    Nav_Func_List_t             FuncList;
    UINT8                       Len = 0;
    INT8                        *MemText[3];
    UINT16                      Free;
    UINT16                      InUsed;
    INT8                        *FreeText;
    INT8                        *InUsedText;
    UINT8                       i;

    Interface = (UI_Normal_NoTitle_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Ta_Desc_t));
    Hal_Mem_Set(Interface, 0, sizeof(UI_Normal_NoTitle_Ta_Desc_t));

    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_MEMORY_STATUS;
    g_ContactsMng.InterfaceCtrl.Ctrl        = (VOID *)Interface;

    Interface->ContLabelTl.TxtId      = PHONE_TEXT_ID_MEM_STA;
    Interface->ContLabelTl.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Interface->ContLabelTl.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    MemText[0] = (INT8 *)(lv_lang_get_text(PHONE_TEXT_ID_PHONE));
    MemText[1] = (INT8 *)(lv_lang_get_text(PHONE_TEXT_ID_SIM1));
    MemText[2] = (INT8 *)(lv_lang_get_text(PHONE_TEXT_ID_SIM2));
    FreeText   = (INT8 *)(lv_lang_get_text(PHONE_TEXT_ID_FREE));
    InUsedText = (INT8 *)(lv_lang_get_text(PHONE_TEXT_ID_IN_USE));

    Len += strlen(MemText[0]) + strlen(MemText[1]) + strlen(MemText[2]) + strlen(FreeText) * 3 +
           strlen(InUsedText) * 3 + 60;

    Interface->ContTa.TaTxt = (INT8 *)Hal_Mem_Alloc(Len);
    Hal_Mem_Set(Interface->ContTa.TaTxt, 0, Len);
    for (i = 0; i < CONTACTS_MEMORY_MAX_NUM; i++)
    {
        InUsed = g_ContactsMng.PhkStatus[i].Used;
        Free   = g_ContactsMng.PhkStatus[i].Total - InUsed;
        sprintf(Interface->ContTa.TaTxt, "%s%s:\n%d %s\n%d %s", Interface->ContTa.TaTxt, MemText[i], Free, FreeText, InUsed, InUsedText);
        if (2 > i)
        {
            sprintf(Interface->ContTa.TaTxt, "%s\n--------\n", Interface->ContTa.TaTxt);
        }
    }

    Interface->ContTa.TaCursorHide = TRUE;
    Interface->ContTa.TaAlign      = LV_ALIGN_IN_TOP_LEFT;

    Interface->ButtonBar.ButtonL.Valid = FALSE;
    Interface->ButtonBar.ButtonM.Valid = FALSE;
    Interface->ButtonBar.ButtonR.Valid = TRUE;
    Interface->ButtonBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Interface->KeyFunc = Contacts_Memory_Status_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_NoTitle_Ta_Create;
    FuncList.OnCreate       = Contacts_Memory_Status_OnCreate;
    FuncList.OnRestoreState = Contacts_Memory_Status_OnRestoreState;
    FuncList.OnDestroy      = Contacts_Memory_Status_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS_MEMORY_STATUS, &FuncList, g_ContactsMng.InterfaceCtrl.Ctrl);
} /* Contacts_Create_Contacts_Memory_Status */

/**
 * Action if pressing memory status button on Contacts_Settings interface
 * param (in) lv_obj_t *Btn,lv_event_t event
 * return  void
 */
void Contacts_Settings_Btn_Memory_Status_Cb(lv_obj_t *Btn,lv_event_t event)
{
    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    Contacts_Create_Contacts_Memory_Status();
}

/**
 * Action if pressing display contacts button on Contacts_Settings interface
 * param (in) lv_obj_t *Btn,lv_event_t event
 * return  void
 */
void Contacts_Settings_Btn_Display_Contacts_Cb(lv_obj_t *Btn,lv_event_t event)
{
    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    Contacts_Create_Contacts_Display();
}

/**
 * Callback function for restoring state on Contacts_Settings interface after backward from another activity
 * param (in) Ctrl: VOID *
 * return  VOID
 */
VOID Contacts_Settings_OnRestoreState(VOID *Ctrl)
{
    g_ContactsMng.InterfaceCtrl.Ctrl        = Ctrl;
    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_SETTINGS;
}

/**
 * Create Contacts_Settings interface
 * param (in) VOID
 * return  VOID
 */
VOID Contacts_Create_Contacts_Settings(VOID)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;
    UINT32                     Len;

    NormalLstOnlyDesc =
        (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    g_ContactsMng.InterfaceCtrl.InterfaceId = ACT_ID_CONTACTS_SETTINGS;
    g_ContactsMng.InterfaceCtrl.Ctrl        = (VOID *)NormalLstOnlyDesc;

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_SETTINGS;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    if (  (CONTACTS_PHONEBOOK_STATUS_SIM_ABSENT == g_ContactsMng.PhonebookStatus[0])
       && (CONTACTS_PHONEBOOK_STATUS_SIM_ABSENT == g_ContactsMng.PhonebookStatus[1]))
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 1;
    }
    else
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 2;
    }
    Len = sizeof(UI_Button_Desc_t) *
          NormalLstOnlyDesc->List.ListButtonCnt;
    NormalLstOnlyDesc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(Len);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, Len);

    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_MEM_STA;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  = Contacts_Settings_Btn_Memory_Status_Cb;
    if (2 == NormalLstOnlyDesc->List.ListButtonCnt)
    {
        NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
        NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
        NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_DISPLAY_CONTACTS;
        NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  =
            Contacts_Settings_Btn_Display_Contacts_Cb;
    }

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Contacts_Normal_List_Interface_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_List_Only_Create;
    FuncList.OnRestoreState = Contacts_Settings_OnRestoreState;
    FuncList.OnDestroy      = Contacts_Normal_List_Interface_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS_SETTINGS, &FuncList, g_ContactsMng.InterfaceCtrl.Ctrl);
} /* Contacts_Create_Contacts_Settings */
